<div class="easyui-layout" data-options="fit:true">
	<!--<div data-options="region:'west',border:true,split:true," title="分类管理" style="width:150px; padding:5px;">
        <ul id="wu-category-tree" class="easyui-tree"></ul>
    </div>-->
	<!-- Begin of toolbar -->
	<div id="wu-toolbar-2">
		<div class="wu-toolbar-button">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
		</div>
		<div class="wu-toolbar-search">
			<label>分类名称：</label><input id="protypename" class="wu-text" style="width:100px">
			<a href="#" class="easyui-linkbutton" onclick="selectRoles()" iconCls="icon-search">开始检索</a>
		</div>
	</div>
	<!-- End of toolbar -->
	<table id="wu-datagrid-2" class="easyui-datagrid" toolbar="#wu-toolbar-2"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-2" class="easyui-dialog" title="添加信息" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="wu-form-2" method="post">
		<table>
			<tr>
				<td width="60" align="right">名称:</td>
				<td><input type="text" name="protypename" class="wu-text" /></td>
			</tr>
		</table>
	</form>
	<div style="text-align:center;padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addRoles()">保存</a>
	</div>
</div>
<div id="wu-dialog-23" class="easyui-dialog" title="修改信息" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="wu-form-23" method="post">
		<table>
			<input type="text" hidden="hidden" name="protypeid" class="wu-text" />
			<tr>
				<td width="60" align="right">名称:</td>
				<td><input type="text" name="protypename" id="rnames" class="wu-text" /></td>
			</tr>
		</table>
	</form>
	<div style="text-align:center;padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="upRoles()">保存</a>
	</div>
</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">
	/**
	 * 页面加载事件
	 */
	$(function() {
		selectRoles();
	})

	/**
	 * 查詢角色信息
	 */
	function selectRoles() {
		$('#wu-datagrid-2').datagrid({
			url: globalData.server + "productType/selectPage",
			queryParams: {
				token: globalData.getToken(),
				protypename: $("#protypename").val()
			},
			onLoadSuccess: function(data) {
				$("a[name='sc']").linkbutton(({
					text: "删除",
					iconCls: "icon-remove",
					//plain: true
				})), $("a[name='bj']").linkbutton(({
					text: "编辑",
					iconCls: "icon-edit",
					//plain: true
				}))
			},
			rownumbers: true,
			pageSize: 5,
			pageList: [5, 10, 20],
			pagination: true,
			multiSort: true,
			fitColumns: true,
			fit: true,
			columns: [
				[{
					field: 'protypename',
					title: '分类名称',
					width: 80
				}, {
					field: 'caozuo',
					title: '修改操作',
					width: 50,
					formatter: uupdate
				}, {
					field: 'caozuo1',
					title: '删除操作',
					width: 50,
					formatter: udelete
				}]
			]
		});
	}

	function uupdate(value, row, index) {
		return "<a class='easyui-linkbutton' name='bj'  onclick='uupdates(" + index +
			")'>修改信息</a>"
	}

	function udelete(value, row, index) {
		return "<a   class='easyui-linkbutton' name='sc'  onclick='udeletes(" + index +
			")'>删除信息</a>"
	}
	//打开添加框
	function openAdd() {
		$("#wu-form-2").form("clear");
		$("#wu-dialog-2").window("open"); //打开窗口
	}
	//保存添加框
	function addRoles() {
		$.messager.confirm('提示', '确认添加吗?', function(r) {
			if(r) {
				$.post(
					globalData.server + "productType/insertProType?token=" + globalData.getToken(),
					$("#wu-form-2").serialize(),
					function(res) {
						if(res = 0) {
							$.messager.alert('提示', "失败");
							return;
						} else {
							$.messager.alert('提示', "成功");
							$("#wu-dialog-2").window("close");
							$("#wu-datagrid-2").datagrid("reload");
						}
					}, "json");
			}

		});
	}
	/**
	 * 修改信息框
	 * @param {Object} index
	 */

	var updateUid;

	function uupdates(index) {
		var data = $("#wu-datagrid-2").datagrid("getData");
		var row = data.rows[index]; //获取验第index行对应的json数据
		updateUid = row.protypeid
		$("#wu-form-23").form("load", row);
		$("#wu-dialog-23").window("open"); //打开窗口
	}
	//保存修改
	function upRoles() {
		$.messager.confirm('提示', '确认修改吗?', function(r) {
			if(r) {
				$.post(
					globalData.server + "productType/updateProType?token=" + globalData.getToken(),
					$("#wu-form-23").serialize(),
					function(res) {
						if(res = 0) {
							$.messager.alert('提示', "失敗");
						} else {
							$.messager.alert('提示', "成功");
							$("#wu-dialog-23").window("close");
							$("#wu-datagrid-2").datagrid("reload");
						}
					}, "json");
			}

		});

	}
	/**
	 * 删除按钮
	 * @param {Object} index
	 */
	function udeletes(index) {
		var delId = $("#wu-datagrid-2").datagrid("getData");
		var row = delId.rows[index].protypeid;
		$.messager.confirm('确认', '您确认想要删除记录吗？', function(r) {
			if(r) {
				$.post(globalData.server + "productType/deleteProType?token=" + globalData.getToken() + "&protypeid=" + row, function(res) {
					if(res == 1) {
						$.messager.alert('删除成功', '成功');
						$("#wu-datagrid-2").datagrid("reload");
					} else {
						$.messager.alert('删除失败', res.no);
					}
				}, "json");
			}
		});
	}
</script>